<?php

$data = $this->calendardata;
$unit = $this->unit;

$criteria = RM_Reservation_Manager::getInstance()->getCriteria();

// get the config
$model = new RM_EnhancedCalendarConfig();
$settings = $model->getSettings()->toArray();
$settings = $settings[0];

// get price system
$config = new RM_Config;
$priceSystem = RM_Prices_Manager::getInstance()->getRealPriceSystem($this->unit);
$peopleMaximums = $priceSystem->getPeopleMaximums($unit->id); // returns array containing "max_occupancy"=>$max_occupancy,"max_adults"=>$max_adults,"max_children"=>$max_children,"max_infants"=>$max_infants
$showTime = $priceSystem->getShowTime(); // returns if the price system needs time values to be selected.

// panel config
$panelsettings = Zend_Json::decode($this->panel->settings);
$align = $panelsettings['align'];

$calStartDate = "";
if (isset($criteria) && $criteria->start_datetime){
    $calStartDate = $criteria->start_datetime;
}
?>

<script type="text/javascript">
// calendar config
var show_day = <?php echo ($settings['show_day'] == "1" ? "true" : "false");?>;
var show_week = <?php echo ($settings['show_week'] == "1" ? "true" : "false");?>;
var show_twoweek = <?php echo ($settings['show_twoweek'] == "1" ? "true" : "false");?>;
var show_month = <?php echo ($settings['show_month'] == "1" ? "true" : "false");?>;
var read_only = <?php echo ($settings['read_only'] == "1" ? "true" : "false");?>;
var show_time = <?php echo ($showTime == "1" ? "true" : "false");?>;
var show_help_popup = <?php echo ($settings['showhelp_popup'] == "1" ? "true" : "false");?>;
var close_onselect = <?php echo ($settings['close_onselect'] == "1" ? "true" : "false");?>;
var fullday_starttime = "<?php echo $settings['fullday_starttime'];?>";
var fullday_endtime = "<?php echo $settings['fullday_endtime'];?>";
var unitName = "<?php echo $unit->name;?>";
var unitID = "<?php echo $unit->id;?>";
var calendarStartDate = "<?php echo $calStartDate;?>";

<?php if (is_array($peopleMaximums)){ ?>
    var adults = <?php echo ((int)$peopleMaximums['max_adults'] == 0 ? 1 : $peopleMaximums['max_adults']);?>;
    var children = <?php echo (int)$peopleMaximums['max_children'];?>;
    var infants = <?php echo (int)$peopleMaximums['max_infants'];?>;
    var maxOccupancy = <?php echo (int)$peopleMaximums['max_occupancy'];?>;
<?php } else { ?>
    var adults = 1;
    var children = 0;
    var infants = 0;
    var maxOccupancy = 1;
<?php } ?>
</script>

<!-- Extensible includes -->
<!-- Extensible includes -->
<link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/resources/css/extensible-all.css" />
<?php
// set if the js files are loaded from debug or live(compressed)...
if ((int)Zend_Registry::get('config')->get('js')->get('debug')->get('user') == 1) {
    ?>
    <script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/extensible-all-debug.js"></script>
    <?php
} else {
    ?>
    <script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/extensible-all.js"></script>
    <?php
}
?>

<!-- Page-specific includes -->
<link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/resources/css/calendar.css"/>

<script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/userdata/modules/EnhancedCalendar/views/user/scripts/EnhancedCalendar/calendar.js"></script>

<!-- App -->
<div class="RM_clear"></div>
<div id="<?php echo $this->panel->getDivID() ?>">
    <div class="rm-enhanced-calendar-container" style="text-align:<?php echo $panelsettings['align'];?>">
        <div id="rm-enhanced-calendar-panel"></div>
    </div>
</div>
<div class="RM_clear"></div>